import 'package:appflutterhomeschool/provider/provider_widget.dart';
import 'package:appflutterhomeschool/res/colors.dart';
import 'package:appflutterhomeschool/res/styles.dart';
import 'package:appflutterhomeschool/ui/widgets/my_app_bar.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/data_statistics_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/detailed_data_widget.dart';
import 'package:appflutterhomeschool/ui/widgets/notice/notice_tab_widget.dart';
import 'package:appflutterhomeschool/view_model/notice/form_details_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

///用户： ninetailedfox
///时间： 2020/7/24
///邮箱： 1037438704@qq.com
///功能： 表单详情
class FormDetailsPage extends StatelessWidget {
  final int notificationId;

  FormDetailsPage({this.notificationId});

  @override
  Widget build(BuildContext context) {
    return ProviderWidget<FormDetailsViewModel>(
      model: FormDetailsViewModel(context, notificationId),
      onModelReady: (value) => value.initView(),
      builder: (context, viewModel, child) {
        return Scaffold(
          resizeToAvoidBottomInset: false,
          backgroundColor: Colours.gray_f6,
          appBar: MyAppBar2(title: "表单详情"),
          body: Stack(
            children: <Widget>[
              Positioned(
                  left: 0,
                  right: 0,
                  top: 0,
                  bottom: ScreenUtil().setWidth(115),
                  child: SingleChildScrollView(
                      child: Column(children: <Widget>[
                    Padding(
                      padding: EdgeInsets.all(ScreenUtil().setWidth(43)),
                      child: Material(
                        borderRadius: BorderRadius.all(Radius.circular(5)),
                        color: Colors.white,
                        elevation: 4.0,
                        child: Column(
                          children: [
                            Padding(
                              padding:
                                  EdgeInsets.all(ScreenUtil().setWidth(43)),
                              child: Row(
                                children: [
                                  Expanded(
                                      child: Text(viewModel?.title ?? "",
                                          style: TextStyles.textDarkBold43)),
                                  Text("进行中", style: TextStyles.textOrange37)
                                ],
                              ),
                            ),
                            Container(
                                alignment: Alignment.centerLeft,
                                padding: EdgeInsets.only(
                                    left: ScreenUtil().setWidth(43)),
                                child: Text(viewModel.datetime,
                                    style: TextStyles.textGray30)),
                            Padding(
                                padding:
                                    EdgeInsets.all(ScreenUtil().setWidth(43)),
                                child: Row(children: [
                                  _columnText(viewModel.shouldBeFilledIn),
                                  _columnText(viewModel.readString),
                                  _columnText(viewModel.readString +
                                      viewModel.shouldBeFilledIn)
                                ])),
                            Container(
                                padding:
                                    EdgeInsets.all(ScreenUtil().setWidth(43)),
                                decoration: BoxDecoration(
                                    border: Border(
                                        top: BorderSide(
                                            color: Colors.grey, width: 0.3))),
                                child: Row(children: [
                                  Expanded(
                                      child: Text("提醒未填写人员",
                                          textAlign: TextAlign.center,
                                          style: TextStyles.textBlue37)),
                                  Expanded(
                                      child: Text("查看未填写人员",
                                          textAlign: TextAlign.center,
                                          style: TextStyles.textBlue37))
                                ])),
                          ],
                        ),
                      ),
                    ),
                    Container(
                      color: Colors.white,
                      child: NoticeTabWidget(
                        //隐藏
                        rightUnread: false,
                        //是否显示
                        openScreen: true,
                        listTab: viewModel.listTab,
                        getIndex: (index) => viewModel.tapModelOnTap(index),
                      ),
                    ),
                    //这个下面两个Widget
                    viewModel.listTab[0].display
                        ? DataStatisticsWidget()
                        : DetailedDataWidget(),
                  ]))),
              Positioned(
                bottom: 0,
                left: 0,
                right: 0,
                child: Material(
                  elevation: 3.0,
                  color: Colors.white,
                  child: Container(
                    height: ScreenUtil().setWidth(114),
                    alignment: Alignment.center,
                    child: Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      mainAxisAlignment: MainAxisAlignment.center,
                      children: [Icon(Icons.print), Text("导出数据")],
                    ),
                  ),
                ),
              ),
            ],
          ),
        );
      },
    );
  }

  Widget _columnText(int sum) {
    return Expanded(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Text("$sum", style: TextStyles.textDarkBold52),
          SizedBox(height: ScreenUtil().setWidth(36)),
          Text("应填写人数", style: TextStyles.textGray27),
        ],
      ),
    );
  }
}
